package com.huaxin.hxmoduleworkorder.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxmoduleworkorder.common.enums.base.BaseCodeEnum;

/**
 * 检查项类型枚举
 */
public enum InspectionTemplateItemType implements BaseCodeEnum {
    CHECK("check", "打勾"),
    MEASURE("measure", "测量值"),
    PHOTO("photo", "拍照"),
    TEXT("text", "文本描述");

    @EnumValue
    private final String code;
    private final String displayName;

    InspectionTemplateItemType(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    /**
     * JSON序列化时输出code字段
     */
    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }


    /**
     * 根据code获取枚举实例
     */
    public static InspectionTemplateItemType of(String code) {
        if (code == null) return null;
        for (InspectionTemplateItemType type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 判断code是否有效
     */
    public static boolean isValid(String code) {
        return of(code) != null;
    }
}
